﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var connectionString = "server=LAPTOP-CUC47BVA\\SQLEXPRESS;database=commodityinfo;uid=sa;pwd=zcq.13870613279";

            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            var table = "select * from Commodity";

            SqlCommand sqlCommand = new SqlCommand(table, sqlConnection);

            //SqlDataReader reader = sqlCommand.ExecuteReader();

            //Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", "Id", "CommodityName", "CommodityPrice", "CommodityOrigin");

            //while (reader.Read())
            //{
            //    Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", reader[0], reader[1], reader[2], reader[3]);

            //}

             

            DataTable dataTable = new DataTable();
             
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(table, sqlConnection);

            sqlDataAdapter.Fill(dataTable);

            foreach(DataRow rows in dataTable.Rows)
            {
                Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", rows["Id"],rows["CommodityName"], rows["CommodityPrice"], rows["ProductOrigin"]);
            }
            ////添加

            //var add = "insert into Commodity values('联想','4000','深圳')";

            //sqlCommand.CommandText = add;

            //sqlCommand.ExecuteNonQuery();

            //// 删除

            //var delete = "delete from Commodity where id=6";

            //sqlCommand.CommandText = delete;

            //sqlCommand.ExecuteNonQuery();

            ////更新

            //sqlDataAdapter.Update(dataTable);

            //sqlConnection.Close();










        }
    }
}
